/*
 * Copyright 2009 Max Kugland
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package org.splink.deepsplink.navigation {
	import org.splink.deepsplink.navigation.command.INavigationCommand;
	import org.splink.library.tree.Tree;

	/**
	 * A factory which creates </code>IPageNavigationController</code> implementation instances.
	 * 
	 * @author Max Kugland
	 */
	public class PageNavigationFactory {

		/**
		 * Creates a navigation controller for a <code>Page</code>. <code>IPageNavigationView</code>s
		 * can be added to the controller. The controller enables the views to 
		 * invoke it's <code>gotoPage</code> method and calls their <code>select</code>
		 * method if they are affected by a <code>gotoPage</code> request.
		 * 
		 * If the <code>Page</code> containing the navigation is finalized it's you might also finalize
		 * the <code>IPageNavigationController</code> and (re)create it during <code>Page</code> 
		 * initialization. 
		 * The added <code>IPageNavigationView</code> instances are subsequently finalized. 
		 * If you don't want to finalize your navigation, because it's creation is expensive, 
		 * you need to accept that the page display is removed from the displaylist after the 
		 * <code>finalize</code> method of the <code>Page</code> has been executed, and added to
		 * the displaylist before <code>initialize</code> is invoked.
		 * 
		 * If you pass 'null' for the pageId you get a navigation for the bottommost pages
		 * 
		 * @param pageId the id of the page
		 * @param tree the page tree
		 * @param navigationCommand a navigation command
		 * 
		 * @return an <code>IPageNavigationController</code>
		 */
		public static function create(pageId : String, tree : Tree, navigationCommand : INavigationCommand) : IPageNavigationController {
			return new PageNavigation(new PageNavigationModel(pageId ? pageId : tree.root.id, tree), navigationCommand);
		}
	}
}
